package com.reservation.controller.user.order;


import com.reservation.dto.user.order.CancelReservation;
import com.reservation.dto.user.order.RefundConfirmDTO;
import com.reservation.result.Result;
import com.reservation.service.OrderService;
import com.reservation.vo.user.order.GetAllOrderVO;
import com.reservation.vo.user.order.GetWaitPayOrderVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "订单相关接口")
@RestController
@RequestMapping("/api/user")
@Slf4j

public class OrderController {

    @Autowired
    private OrderService orderService;

    //获取全部订单接口
    @PostMapping("/getAllOrder")
    public Result getAllOrder() {

        List<GetAllOrderVO> list = orderService.getAllOrders();
        return Result.success(list);
    }

    //获取待支付订单接口
    @PostMapping("/getWaitPayOrder")
    public Result getWaitPayOrder() {

        List<GetWaitPayOrderVO> list = orderService.getWaitPayOrder();
        return Result.success(list);
    }

    //获取可取消订单接口
    @PostMapping("/getCancelableOrder")
    public Result getCancelableOrderList() {

        List<GetAllOrderVO> list = orderService.getCancelableOrderList();
        return Result.success(list);
    }

    //取消预约接口
    @PostMapping("/cancelReservation")
    public Result cancelReservation(@RequestBody CancelReservation dto) {

        return orderService.cancelOrder(dto) ? Result.success("提交取消成功！") : Result.error("提交取消失败！");
    }

    //获取待审核订单接口
    @PostMapping("/getWaitAuditOrder")
    public Result getWaitAuditOrder() {

        List<GetAllOrderVO> list = orderService.getWaitAuditOrderList();
        return Result.success(list);
    }

    //确认取消预订接口
    @PostMapping("/confirmCancelReservation")
    public Result confirmCancelReservation(@RequestBody RefundConfirmDTO refundConfirmDTO) {
        log.info("客户确认退款请求: {}", refundConfirmDTO);
        return orderService.confirmCancelOrder(refundConfirmDTO) ?
                Result.success("确认成功！成功取消订单并退款到钱包！") :
                Result.error("确认失败！");
    }


}
